const formatTime = date => {
        const year = date.getFullYear()
        const month = date.getMonth() + 1
        const day = date.getDate()
        const hour = (date.getHours()) 
        const minute = date.getMinutes()
        const second = date.getSeconds()

        return [minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
        n = n.toString()
        return n[1] ? n : '0' + n
}

module.exports = {
        formatTime: formatTime
}



var CryptoJS= require('aes.js');
var key = CryptoJS.enc.Utf8.parse("十六进制数作为秘钥");
var iv = CryptoJS.enc.Utf8.parse('十六进制数作为秘钥偏移量');
// AES加密
function Encrypt(word) {
        var srcs = CryptoJS.enc.Utf8.parse(word);
        var encrypted = CryptoJS.AES.encrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 });
        return encrypted.ciphertext.toString().toUpperCase();
        //toString()  转字符串   toUpperCase()  转换成大写
}
// AES解密
function Decrypt(word) {
        var encryptedHexStr = CryptoJS.enc.Hex.parse(word);
        var srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr);
        var decrypt = CryptoJS.AES.decrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 });
        var decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
        return decryptedStr.toString();
}







function formhttp(url, method, data, header,collBack) {
        wx.request({
                url: url,
                method: method,
                data: data,
                header: header,
                success: (res) => {
                        if (collBack) {
                                collBack(res.data);
                        }
                },
                fail: (error) => {
                        console.log(error);
                }
        })
}

function promotion(url, method, data, collBack) {
        wx.request({
                url: url,
                method: method,
                data: data,
                header: {
                        'content-type': 'application/x-www-form-urlencoded'
                },
                success: (res) => {
                        if (collBack) {
                                collBack(res.data);
                        }
                },
                fail: (error) => {
                        console.log(error);
                }
        })
}


module.exports = {
        formhttp: formhttp,
        promotion: promotion,
        
        Encrypt: Encrypt,
        Decrypt: Decrypt
}
